Be proactive about checking for error codes.#316
Conversation
In order to be sure I've correctly understood you, below my attempt at rewording our previous discussion
Provided I correctly got the underlying intent, I don't disagree. This may indeed be beneficial and add some kind of safety net. However, I wonder if we could even push this a little bit further. Libgit2 exposes 4 kinds of functions:
How about modifying the
Note: Knowing that I'm awfully bad at Naming Things, I'm of course completely open to counter-proposals regarding the names of the Note 2: @phkelley recently fixed Beside this, I've got some more nitpicks for you:
|
|
This seems like smart future-proofing to me. As for names, I suggest: void Ensure.Success(res); // I don't see a reason to change this
bool Ensure.BooleanResult(res);
int Ensure.Int32Result(res); |
|
In order to have all the methods on the same semantic level, how about
|
|
Thank you, @nulltoken, as usual you were much more eloquent than I was. Love @dahlbyk 's suggestions. (I realize this isn't super high-pri but I was thinking about changing a func in |
To me, preventing the developer from shooting in the user's foot is quite a high priority 😉 If you find the time to work on this PR, I'll be happy to merge it. However, if your Todo list is already full, please just say so, I'm sure somebody will be happy to tackle this. |
|
As one who shoots ones self in ones foot quite frequently, I appreciate that. I'm happy to go down this road - my todo list just got a lot shorter! |
👍 |
|
OK, I think I got everything...! I noticed that the binding for |
|
💟 Long live the Interop King! |
For libgit2 functions that return 0 or 1, as if it were a Boolean value, we may assume that there is no error and simply check whether the return code was non-zero. In the case of
git_index_has_conflicts, this is not a problem, as the libgit2 function will always return 0 or 1.We could be proactive about this and check for < 0 as well - if someone were to change the libgit2 implementation, they may assume that bindings are checking for < 0 to indicate error and make changes in that manner.
This is really to open up for discussion whether we want to be proactive in this manner or not.